import Taro from '@tarojs/taro';
import { View, Image, Button } from '@tarojs/components';
import { get as getGlobalData, set as setGlobalData } from '@/global'
import utils from '@/utils/util'
import http from '@/utils/http'
import './index.scss'

export default class Setting extends Taro.Component {
    constructor() {
        super();
        this.state = {
            userInfo: null,
            imgbaseUrl: process.env.IMG_URL
        }
    }
    componentWillMount() {
        let userInfo = getGlobalData('userInfo') || utils.getUserInfo();
        this.setState({
            userInfo
        })
    }
    loginout() {
        let { userInfo } = this.state;
        http.post('logout', {
            userid: userInfo.id
        }, false, true, false).then((res) => {
            Taro.removeStorageSync('userInfo')
            setGlobalData('userInfo', null);
            Taro.reLaunch({
                url: '/pages/login/index'
            })
        }).catch((e) => {
            console.log(e)
        })
    }
    config = {
        navigationBarTitleText: '设置'
    }
    render() {
        const { userInfo, imgbaseUrl } = this.state
        return (
            <View className='setting-box pt-2-5'>
                <View className='user-info pl-2-5  pt-3 bg_fff box_s ov_h'>
                    <View className=''>
                        {userInfo.organization}
                    </View>
                    <View className='info p-3 flex flex-item-v-center pb-5' >
                        <Image src={imgbaseUrl + userInfo.file} className='info-img' ></Image>
                        <View className='pl-6 flex-1'>
                            <View className='ft32 ft_w600'>姓名：{userInfo.name}</View>
                            <View className='mt-4 ft28 fc_B9C'>工号：{userInfo.loginid}</View>
                            <View className='mt-2 ft28 fc_B9C'>科室：{userInfo.departmentname}</View>
                            <View className='mt-2 ft28 fc_B9C'>负责：{userInfo.wardname}</View>
                        </View>
                    </View>
                </View>
                {userInfo && userInfo.groupid === 1 && <View className='mt-2-5 bg_fff pl-6 pt-2-5 pb-2-5 flex flex-r flex-item-between flex-item-v-center pr-2 de-btn' onClick={() => {
                    Taro.navigateTo({
                        url: '/pages/setting/messageSetting/index'
                    })
                }}
                >
                    <View>
                        <View className='ft28' >消息提醒</View>
                        <View className='ft24 fc_B9C mt-1-5'>开启后，微信将向你推送消息通知</View>
                    </View>
                    <View>
                        <Image className='ml-0-5' style={{ width: Taro.pxTransform(12), height: Taro.pxTransform(22), opacity: 0.6 }} src={require('../../assets/imgs/home/home_icon_pressed.png')} />
                    </View>
                </View>}

                <View className='mt-2-5 bg_fff pl-2-5  flex pr-2 de-btn'>
                    <View className='line-b flex-1 pt-3-5 pb-3-5 flex flex-r flex-item-between flex-item-v-center'>
                        <View className='ft28 pl-3-5'>使用帮助</View>
                        <View>
                            <Image className='ml-0-5' style={{ width: Taro.pxTransform(12), height: Taro.pxTransform(22), opacity: 0.6 }} src={require('../../assets/imgs/home/home_icon_pressed.png')} />
                        </View>
                    </View>
                </View>
                <Button open-type='feedback'>
                    <View className='bg_fff flex pr-2 pl-2-5 de-btn'>
                        <View className='line-b pt-3-5 pb-3-5 flex-1 flex flex-r flex-item-between flex-item-v-center'>
                            <View className='ft28 pl-3-5'>建议反馈</View>
                            <View>
                                <Image className='ml-0-5' style={{ width: Taro.pxTransform(12), height: Taro.pxTransform(22), opacity: 0.6 }} src={require('../../assets/imgs/home/home_icon_pressed.png')} />
                            </View>
                        </View>
                    </View>
                </Button>
                <View className='bg_fff pl-2-5 flex pr-2 de-btn' onClick={() => {
                    Taro.navigateTo({
                        url: '/pages/setting/aboutUs/index'
                    })
                }}
                >
                    <View className='pt-3-5 pb-3-5 flex-1 flex flex-r flex-item-between flex-item-v-center'>
                        <View className='ft28 pl-3-5'>关于我们</View>
                        <View>
                            {/* <Text className='ft24 fc_B9C pr-2'>V1.1.0</Text> */}
                            <Image className='ml-0-5' style={{ width: Taro.pxTransform(12), height: Taro.pxTransform(22), opacity: 0.6 }} src={require('../../assets/imgs/home/home_icon_pressed.png')} />
                        </View>
                    </View>
                </View>
                <View className='bg_fff pl-2-5 flex pr-2 de-btn' onClick={() => {
                    Taro.navigateTo({
                        url: '/pages/setting/updatePassword/index'
                    })
                }}
                >
                    <View className='pt-3-5 pb-3-5 flex-1 flex flex-r flex-item-between flex-item-v-center'>
                        <View className='ft28 pl-3-5'>修改密码</View>
                        <View>
                            <Image className='ml-0-5' style={{ width: Taro.pxTransform(12), height: Taro.pxTransform(22), opacity: 0.6 }} src={require('../../assets/imgs/home/home_icon_pressed.png')} />
                        </View>
                    </View>
                </View>
                <View className='mt-2-5 bg_fff pl-2-5 flex pr-2 de-btn' onClick={() => {
                    this.loginout();
                }}
                >
                    <View className='pt-3-5 pb-3-5 flex-1 flex flex-r flex-item-between flex-item-v-center'>
                        <View className='ft28 pl-3-5'>退出登录</View>
                    </View>
                </View>
            </View>
        )
    }
}
